package main

import (
	"fmt"
	"sync"

	"gitee.com/technology-to-share/concurrency-of-shared-variables/example6/bank"
)

//重入锁 和 Balance为什么要加锁的演示
func main() {
	for i := 0; i < 1000000; i++ {
		test1()
	}
}

func test1() {
	bank.Init()
	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		defer wg.Done()
		bank.Withdraw(101)
	}()

	go func() {
		defer wg.Done()
		b := bank.Balance()
		if b != 100 {
			fmt.Println("==", b)
		}
	}()
	wg.Wait()
}
